<?php

declare(strict_types=1);

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

class Payout extends Model
{
    use SoftDelete;

    protected $name = 'payout';

    protected $autoWriteTimestamp = 'datetime';

    protected $append = ['status_label'];

    public const STATUS_PENDING = 0;
    public const STATUS_PROCESSING = 1;
    public const STATUS_PAID = 2;
    public const STATUS_FAILED = 3;

    public static function statusMap(): array
    {
        return [
            self::STATUS_PENDING => '待处理',
            self::STATUS_PROCESSING => '处理中',
            self::STATUS_PAID => '已支付',
            self::STATUS_FAILED => '支付失败',
        ];
    }

    public function statement()
    {
        return $this->belongsTo(SellerStatement::class, 'statement_id');
    }

    public function org()
    {
        return $this->belongsTo(Org::class, 'seller_org_id');
    }

    public function getStatusLabelAttr(): string
    {
        return self::statusMap()[(int) $this->status] ?? '未知状态';
    }
}
